﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Assessment.Management.SharedComponent.Params.ManagerParam;
using Assessment.Management.SharedComponent.Constants;
using Assessment.Management.BIZ;
using Assessment.Management.SharedComponent.Entities;

namespace Assessment.Management.UI.Admin.UserControls.Statistic
{
    public partial class PollDisplay : System.Web.UI.UserControl
    {
        #region events
        protected void Page_Load(object sender, EventArgs e)
        {

            if (!IsPostBack)
            {
                string id = GetParam();
                hdID.Value = GetParam();
                if (!string.IsNullOrEmpty(id))
                {
                    BindData(id);
                }
                else
                {
                    GotoViewPage();
                }
            }
        }

        protected void btnEdit_Click(object sender, EventArgs e)
        {
            Response.Redirect("/UI/Admin/UniAdmin.aspx?do=polledit&id=" + hdID.Value);
        }

        protected void btnExit_Click(object sender, EventArgs e)
        {
            Response.Redirect("/UI/Admin/UniAdmin.aspx?do=pollsetting");
        }
        #endregion

        #region methods
        private void GotoViewPage()
        {
            Response.Redirect("/UI/Admin/UniAdmin.aspx?do=pollsetting");
        }

        private void BindData(string id)
        {
            PollParam param = GetPollByID(id);
            BindItemToForm(param);
        }

        private PollParam GetPollByID(string id)
        {
            PollParam param = new PollParam(FunctionType.GetPollByID);
            param.Poll = new Poll() { ID = id };
            MainController.Provider.Execute(param);
            return param;
        }

        private void BindItemToForm(PollParam param)
        {
            lblPassword.Text = param.Poll.Password;
            lblTeacherName.Text = param.Poll.TeacherName;
            lblClassName.Text = param.Poll.ClassName;
            lblSubjectName.Text = param.Poll.SubjectName;
        }

        private string GetParam()
        {
            return Request.QueryString["id"];
        }
        #endregion
    }
}